package com.huike.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huike.utils.JsonUtilsForRichText;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.huike.entity.Policy;
import com.huike.service.IPolicyService;

import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Lwen
 * @since 2019-11-12
 */
@RestController
@RequestMapping("/policy")
public class PolicyController {

	@Autowired
	IPolicyService iPolicyService;

	/**
	 * 读取所有最新政策信息到《最新政策》模块
	 * @return
	 */
	@RequestMapping("/getPolicyAction")
	@ResponseBody
	public void getPolicyAction(HttpServletResponse response, int page, int limits) {
		IPage<Policy> iPage = iPolicyService.listByPage(page, limits);
		Map<String, Object> map = new HashMap<>();
		map.put("code", 0);
		map.put("total", iPage.getTotal());
		map.put("data", iPage.getRecords());
		JsonUtilsForRichText.jsonArray(map, response);
	}
	
	/**
	 * 根据最新政策的ID读取相应的数据到newPolicyDetail.jsp页面展示
	 * @param id
	 * @return
	 */
	@RequestMapping("/getNewPolicyDetail")
	@ResponseBody
	public Policy getNewPolicyDetail(String id){
		Policy policy = iPolicyService.getById(id);
		return policy;
	}

}
